#pragma once

#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

class InetAddr
{
public:
    InetAddr()
    {
    }

    InetAddr(const sockaddr_in addr)
        : _addr(addr)
    {
        Init(addr);
    }

    void Init(const sockaddr_in& addr)
    {
        _ip = inet_ntoa(addr.sin_addr);
        _port = ntohs(addr.sin_port);

        _user += _ip;
        _user += " : ";
        _user += std::to_string(_port);
        _addr = addr;
    }

    std::string &GetUser()
    {
        return _user;
    }

    std::string &GetIp()
    {
        return _ip;
    }

    uint16_t &GetPort()
    {
        return _port;
    }

    sockaddr_in &GetAddr()
    {
        return _addr;
    }

private:
    std::string _ip;
    uint16_t _port;
    sockaddr_in _addr;
    std::string _user;
};